#include <iostream>
#include <bitset>
using namespace std;

int main()
{
	bool op1 = false, op2 = false;

	cout << (op1 && op2) << endl;
	cout << (op1 || op2) << endl;
	cout << (!op1) << endl;

	unsigned short inputNum = 2;

	bitset<8> inputBits(inputNum);
	cout << inputNum << " 2进制 " << inputBits << endl;

	bitset<8> bitwiseNOT = (~inputNum);
	cout << "Bitwise NOT ~" << endl;
	cout << "~" << inputBits << " = " << bitwiseNOT << endl;

	cout << "Bitwise AND, & with 00001111" << endl;
	bitset<8> bitwiseAND = (0x0F & inputNum);// 0x0F is hex for 0001111
	cout << "0001111 & " << inputBits << " = " << bitwiseAND << endl;

	cout << "Bitwise OR, | with 00001111" << endl;
	bitset<8> bitwiseOR = (0x0F | inputNum);
	cout << "00001111 | " << inputBits << " = " << bitwiseOR << endl;

	cout << "Bitwise XOR, ^ with 00001111" << endl;
	bitset<8> bitwiseXOR = (0x0F ^ inputNum);
	cout << "00001111 ^ " << inputBits << " = " << bitwiseXOR << endl;
	//
	int halfNum = inputNum >> 1;
	int quarterNum = inputNum >> 2;
	int doubleNum = inputNum << 1;
	int quadrupleNum = inputNum << 2;

	cout << quarterNum << endl;
	cout << halfNum << endl;
	cout << doubleNum << endl;
	cout << quadrupleNum << endl;
	//
	inputNum += 8;
	cout << "After += 8, value = " << inputNum << endl;
	inputNum -= 2;
	cout  << inputNum << endl;
	inputNum /= 4;
	cout  << inputNum << endl;
	inputNum *= 4;
	cout  << inputNum << endl;
	inputNum %= 1000;
	cout  << inputNum << endl;

	// Note: henceforth assignment happens within cout 
	cout << "After <<= 1, value = " << (inputNum <<= 1) << endl;
	cout << "After >>= 2, value = " << (inputNum >>= 2) << endl;

	cout << "After |= 0x55, value = " << (inputNum |= 0x55) << endl;
	cout << "After ^= 0x55, value = " << (inputNum ^= 0x55) << endl;
	cout << "After &= 0x0F, value = " << (inputNum &= 0x0F) << endl;


	return 0;
}